package com.erp.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.erp.common.R;
import com.erp.entity.Product;
import com.erp.service.ProductService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @PostMapping
    public R<String> save(@RequestBody Product product){
        productService.save(product);
        return R.success("保存成功");
    }

    @GetMapping
    @RequiresPermissions(value = "LogisticsAdministrator:list")
    public R<List<Product>> findAll(){
        LambdaQueryWrapper<Product> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.orderByAsc(Product::getId);

        List<Product> list = productService.list(lambdaQueryWrapper);
        return R.success(list);
    }

}
